/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thienphuc.patient.dao.impl;

import java.util.List;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import thienphuc.patient.dao.AbstractHibernateDaoSupport;
import thienphuc.patient.dao.ThuocDAO;
import thienphuc.patient.dto.NhomThuoc;
import thienphuc.patient.dto.Thuoc;

/**
 *
 * @author QuocDat
 */
public class ThuocDAOImpl extends AbstractHibernateDaoSupport<Thuoc, Integer> implements ThuocDAO {

    public ThuocDAOImpl(Class<Thuoc> classPersistent) {
        super(classPersistent);
    }

    public List<Thuoc> findByTenThuoc(String tenThuoc) throws Exception {
        Criterion criterionTenThuoc = Restrictions.like(THUOC_TEN_THUOC, "%" + tenThuoc + "%");
        return this.findByCriteria(criterionTenThuoc);
    }

    public List<Thuoc> findByTenThuocAndTrangThai(String tenThuoc, boolean trangThai) throws Exception {
        Criterion criterionTenThuoc = Restrictions.like(THUOC_TEN_THUOC, "%" + tenThuoc + "%");
        Criterion criterionTrangThai = Restrictions.eq(THUOC_TRANG_THAI, trangThai);
        
        return this.findByCriteria(criterionTenThuoc, criterionTrangThai);
    }

    public List<Thuoc> findByNhomThuoc(NhomThuoc nhomThuoc) throws Exception {
        return this.findByProperty(THUOC_NHOM_THUOC, nhomThuoc);
    }

    public List<Thuoc> findByNhomThuocAndTrangThai(NhomThuoc nhomThuoc, boolean trangThai) throws Exception {
        Criterion criterionNhomThuoc = Restrictions.eq(THUOC_NHOM_THUOC, nhomThuoc);
        Criterion criterionTrangThai = Restrictions.eq(THUOC_TRANG_THAI, trangThai);

        return this.findByCriteria(criterionNhomThuoc, criterionTrangThai);
    }

    public List<Thuoc> findByGiaBan(double giaBanMin, double giaBanMax) throws Exception {
        Criterion criterionGiaBan = Restrictions.between(THUOC_GIA_BAN, giaBanMin, giaBanMax);
        return this.findByCriteria(criterionGiaBan);
    }

    public List<Thuoc> findByTrangThai(boolean trangThai) throws Exception {
        return this.findByProperty(THUOC_TRANG_THAI, trangThai);
    }
}
